import os

basedir = os.path.abspath(os.path.dirname(__file__))
# 获取这个文件夹的路径，然后转换为绝对路径


class Config:
    SECRET_KEY = os.environ.get(
        'SECRET_KEY') or 'hard to guess string'  # 设置加密字符串，如果没有全局变量，就是后面这个
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    FLASKY_MAIL_SUBJECT_PREFIX = '[BBblog]'
    FLASKY_MAIL_SENDER = 'FLASK Admin <1874217870@qq.com>'
    FLASKY_ADMIN = os.environ.get('BBblog_ADMIN') or '1874217870@qq.com'
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    MAIL_SERVER = 'smtp.qq.com'  # 打错了，我是真的傻逼， smtp.qq.com
    MAIL_PORT = 587
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME') or '1874217870@qq.com'
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') or 'pfwqqvoazzihdjij'
    # 独立密码使用不了了，使用授权密码 : pfwqqvoazzihdjij
    FLASKY_POSTS_PER_PAGE = os.environ.get(
        'FLASKY_POSTS_PER_PAGE') or 10  # 博客分页
    FLASKY_FOLLOWERS_PER_PAGE = os.environ.get(
        'FLASKY_POSTS_PER_PAGE') or 10  # 关注分页
    WHOOSH_BASE = os.path.join(basedir, 'BASE_INDEX')
    # SERVER_NAME = 'bbblog.icu'
    ssl_context = ('certificate/full_chain.pem', 'certificate/private.key')

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):  # 开发环境
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'mysql://1874217870:shibuqi123+++@bbblog.icu:3306/flask_blog'
    # DATABASE_URI = 'mysql+mysqlconnector://{user}:{password}@{server}/{database}'.format(
    # user='1874217870', password='shibuqi123+++', server='bbblog.icu', database='flask_blog')


class TestingConfig(Config):  # 测试sqlite
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')


class ProductionConfig(Config):  # 生产环境
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data.sqlite')


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}
